#ifndef __INIT__H__
#define __INIT__H__

#include "conn.h"
#include "tpool.h"
#include "conf.h"
#include "msg.h"

#define LISTENQ 100


typedef  void (*SCB)(msg_t* msg);

typedef  struct _ctx{
    conf_t conf;
    tpool_t tp;
    conn_tab_t conn_tab;
    
    int server_id;	
     struct sockaddr_in server_addr; 
   //  int server_port;
	 
     int listenfd;			 // listen socked fd
     pthread_t listen_pid;          // listen thread pid
     pthread_t reconn_pid;
     int epfd;                              //epoll fd

     queue_t recv_msg_q;           //recevied msg queue
     SCB send_callback_fun;	

    queue_t reconn_q;   //reconnect q	 

}ctx_t;


typedef struct  cb_arg{
	conn_t* conn;
	msg_t*  msg;
}cb_arg_t;


extern ctx_t  g_ctx;

extern int get_local_id();


extern int sys_init(int server_id, SCB scb_fun);
extern void set_send_callback(SCB scb_fun);

extern int sys_exit();

extern int send_data_sync(int id, char* buf, int len);
extern rval_t send_data_async(int id, char* buf, int len);
extern int send_msg_ack(msg_t* msg);

extern msg_t* recv_data();


#endif

